package com.dmx.fw.web.struts2.action.auth;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.dmx.cep.service.ContentService;
import com.dmx.fw.constant.SecurityConstant;
import com.dmx.fw.security.CustomJdbcDaoImpl;
import com.dmx.fw.security.bean.MenuBean;
import com.dmx.fw.security.bean.Operator;
import com.dmx.fw.web.struts2.action.BaseAction;
import com.opensymphony.xwork2.ActionContext;

public class LoginAction extends BaseAction {
	List<MenuBean> newMenus;
	private String cepLicenseVersion;
	private CustomJdbcDaoImpl userDetailsService;
	private Integer nodeId;
	private List<Object[]> nodeIdList;
	
	private ContentService contentService;
	
	private int captionTaskCounts=0;
	/**
	 * 自定义登录页面访问路径
	 */
	public String customLogin(){
		String login_error = ServletActionContext.getRequest().getParameter("login_error");
		if("1".equals(login_error)){
			String error_message = "认证失败，请检查用户名密码是否正确";
			ServletActionContext.getRequest().setAttribute("error_message", error_message);
		}
		return "login";
	}
	
	public String loginSuccess(){
		Operator operator = (Operator)(ServletActionContext.getRequest().getSession().getAttribute(SecurityConstant.OPERATOR_SESSION_KEY));
		ActionContext.getContext().getSession().put(com.dmx.platform.Constants.OWNERID, "8");
		nodeIdList = userDetailsService.findNodeIdList();
		if(nodeId==null||"".equals(nodeId)){
			nodeId= (Integer)nodeIdList.get(0)[0];
		}
		newMenus = userDetailsService.loadUserAndNodeMenus(operator.getLogin(), nodeId);
	
		return "main";
	}

	public void setUserDetailsService(CustomJdbcDaoImpl userDetailsService) {
		this.userDetailsService = userDetailsService;
	}

	
	
	

	public Integer getNodeId() {
		return nodeId;
	}

	public void setNodeId(Integer nodeId) {
		this.nodeId = nodeId;
	}

	public List<Object[]> getNodeIdList() {
		return nodeIdList;
	}

	public List<MenuBean> getNewMenus() {
		return newMenus;
	}

	public ContentService getContentService() {
		return contentService;
	}

	public void setContentService(ContentService contentService) {
		this.contentService = contentService;
	}

	public int getCaptionTaskCounts() {
		return captionTaskCounts;
	}

	public void setCaptionTaskCounts(int captionTaskCounts) {
		this.captionTaskCounts = captionTaskCounts;
	}

	public void setCepLicenseVersion(String cepLicenseVersion) {
		this.cepLicenseVersion = cepLicenseVersion;
	}

	public String getCepLicenseVersion() {
		return cepLicenseVersion;
	}
	
	

}
